"""
@author: 江同学呀
@file: agg_common.py
@date: 2025/1/7 23:38
@desc: 
"""

from espc.common.common import ASC, DESC
from espc.utils.enum_utils import EnumBase


class OrderType(EnumBase):
    """
    排序类型
    """
    asc = ASC
    desc = DESC


class CollectMode(EnumBase):
    """
    收集模式
    """
    breadth_first = "breadth_first"
    depth_first = "depth_first"


class ExecutionHint(EnumBase):
    """
    执行提示
    """
    map = "map"
    global_ordinals = "global_ordinals"
    bytes_hash = "bytes_hash"


class MinimumInterval(EnumBase):
    """
    最小间隔参数
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-bucket-autodatehistogram-aggregation.html#_minimum_interval_parameter
    """
    year = "year"
    month = "month"
    day = "day"
    hour = "hour"
    minute = "minute"
    second = "second"


class CalendarInterval(EnumBase):
    """
    日历间隔参数
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-bucket-datehistogram-aggregation.html#calendar_intervals
    """
    year = "year"
    """
    One year is the interval between the start day of the month and time of day and the same day of the month and time 
    of day the following year in the specified time zone, so that the date and time are the same at the start and end.
    一年是该月的开始日期与 日期和次年的月份的同一天和时间 指定时区，以便 start 和 end 的日期和时间相同。
    """
    y1 = "1y"
    """
    One year is the interval between the start day of the month and time of day and the same day of the month and time 
    of day the following year in the specified time zone, so that the date and time are the same at the start and end.
    一年是该月的开始日期与 日期和次年的月份的同一天和时间 指定时区，以便 start 和 end 的日期和时间相同。
    """
    quarter = "quarter"
    """
    One quarter is the interval between the start day of the month and time of day and the same day of the month and 
    time of day three months later, so that the day of the month and time of day are the same at the start and end.
    四分之一是该月的开始日期与 当月的时间和三个月后的当月的同一天和当天的时间， 因此，月份中的日期和时间在开始和结束时是相同的。
    """
    q1 = "1q"
    """
    One quarter is the interval between the start day of the month and time of day and the same day of the month and 
    time of day three months later, so that the day of the month and time of day are the same at the start and end.
    四分之一是该月的开始日期与 当月的时间和三个月后的当月的同一天和当天的时间， 因此，月份中的日期和时间在开始和结束时是相同的。
    """
    month = "month"
    """
    One month is the interval between the start day of the month and time of day and the same day of the month and time 
    of the following month in the specified time zone, so that the day of the month and time of day are the same at the 
    start and end.
    一个月是指定时区中当月的开始日期和当月时间与下一个月的同一天和时间之间的间隔，因此该月的起始日期和一天中的时间在开始和结束时相同。
    """
    M1 = "1M"
    """
    One month is the interval between the start day of the month and time of day and the same day of the month and time 
    of the following month in the specified time zone, so that the day of the month and time of day are the same at the 
    start and end.
    一个月是指定时区中当月的开始日期和当月时间与下一个月的同一天和时间之间的间隔，因此该月的起始日期和一天中的时间在开始和结束时相同。
    """
    week = "week"
    """
    One week is the interval between the start day_of_week:hour:minute:second and the same day of the week and time of 
    the following week in the specified time zone.
    一周是指定时区的开始 day_of_week：hour：minute：second 与指定时区的一周同一天和下一周的时间之间的间隔。
    """
    w1 = "1w"
    """
    One week is the interval between the start day_of_week:hour:minute:second and the same day of the week and time of 
    the following week in the specified time zone.
    一周是指定时区的开始 day_of_week：hour：minute：second 与指定时区的一周同一天和下一周的时间之间的间隔。
    """
    day = "day"
    """
    All days begin at the earliest possible time, which is usually 00:00:00 (midnight). One day (1d) is the interval 
    between the start of the day and the start of the following day in the specified time zone, compensating for any 
    intervening time changes.
    所有日期都从尽可能早的时间开始，通常是 00：00：00 （午夜）。一天 （1d） 是指定时区的一天开始和第二天开始之间的间隔，用于补偿其间的任何时间变化。
    """
    d1 = "1d"
    """
    All days begin at the earliest possible time, which is usually 00:00:00 (midnight). One day (1d) is the interval 
    between the start of the day and the start of the following day in the specified time zone, compensating for any 
    intervening time changes.
    所有日期都从尽可能早的时间开始，通常是 00：00：00 （午夜）。一天 （1d） 是指定时区的一天开始和第二天开始之间的间隔，用于补偿其间的任何时间变化。
    """
    hour = "hour"
    """
    All hours begin at 00 minutes and 00 seconds. One hour (1h) is the interval between 00:00 minutes of the first hour 
    and 00:00 minutes of the following hour in the specified time zone, compensating for any intervening leap seconds, 
    so that the number of minutes and seconds past the hour is the same at the start and end.
    所有小时都从 00 分 00 秒开始。一小时 （1h） 是指定时区中第一个小时的 00：00 分钟与下一小时的 00：00 分钟之间的间隔，用于补偿任何中间的闰
    秒，因此该小时之后的分钟数和秒数在开始和结束时相同。
    """
    h1 = "1h"
    """
    All hours begin at 00 minutes and 00 seconds. One hour (1h) is the interval between 00:00 minutes of the first hour 
    and 00:00 minutes of the following hour in the specified time zone, compensating for any intervening leap seconds, 
    so that the number of minutes and seconds past the hour is the same at the start and end.
    所有小时都从 00 分 00 秒开始。一小时 （1h） 是指定时区中第一个小时的 00：00 分钟与下一小时的 00：00 分钟之间的间隔，用于补偿任何中间的闰
    秒，因此该小时之后的分钟数和秒数在开始和结束时相同。
    """
    minute = "minute"
    """
    All minutes begin at 00 seconds. One minute is the interval between 00 seconds of the first minute and 00 seconds 
    of the following minute in the specified time zone, compensating for any intervening leap seconds, so that the 
    number of minutes and seconds past the hour is the same at the start and end.
    所有分钟都从 00 秒开始。一分钟是指定时区中第一分钟的 00 秒和下一分钟的 00 秒之间的间隔，补偿任何中间的闰秒，因此小时后的分钟数和秒数在开始
    和结束时相同。
    """
    m1 = "1m"
    """
    All minutes begin at 00 seconds. One minute is the interval between 00 seconds of the first minute and 00 seconds 
    of the following minute in the specified time zone, compensating for any intervening leap seconds, so that the 
    number of minutes and seconds past the hour is the same at the start and end.
    所有分钟都从 00 秒开始。一分钟是指定时区中第一分钟的 00 秒和下一分钟的 00 秒之间的间隔，补偿任何中间的闰秒，因此小时后的分钟数和秒数在开始
    和结束时相同。
    """


class FixedInterval(EnumBase):
    """
    固定间隔
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/search-aggregations-bucket-datehistogram-aggregation.html#fixed_intervals
    """
    milliseconds = "milliseconds"
    """
    A single millisecond. This is a very, very small interval.
    一毫秒。这是一个非常非常小的间隔。
    """
    ms = "ms"
    """
    A single millisecond. This is a very, very small interval.
    一毫秒。这是一个非常非常小的间隔。
    """
    seconds = "seconds"
    """
    Defined as 1000 milliseconds each.
    定义为每个 1000 毫秒。
    """
    s = "s"
    """
    Defined as 1000 milliseconds each.
    定义为每个 1000 毫秒。
    """
    minutes = "minutes"
    """
    Defined as 60 seconds each (60,000 milliseconds). All minutes begin at 00 seconds.
    定义为每个 60 秒（60,000 毫秒）。所有分钟都从 00 秒开始。
    """
    m = "m"
    """
    Defined as 60 seconds each (60,000 milliseconds). All minutes begin at 00 seconds.
    定义为每个 60 秒（60,000 毫秒）。所有分钟都从 00 秒开始。
    """
    hours = "hours"
    """
    Defined as 60 minutes each (3,600,000 milliseconds). All hours begin at 00 minutes and 00 seconds.
    定义为每个 60 分钟（3,600,000 毫秒）。所有小时都从 00 分 00 秒开始。
    """
    h = "h"
    """
    Defined as 60 minutes each (3,600,000 milliseconds). All hours begin at 00 minutes and 00 seconds.
    定义为每个 60 分钟（3,600,000 毫秒）。所有小时都从 00 分 00 秒开始。
    """
    days = "days"
    """
    Defined as 24 hours (86,400,000 milliseconds). All days begin at the earliest possible time, which is usually 00:00:00 (midnight).
    定义为 24 小时（86,400,000 毫秒）。所有日期都从最早的时间开始，通常是 00：00：00（午夜）。
    """
    d = "d"
    """
    Defined as 24 hours (86,400,000 milliseconds). All days begin at the earliest possible time, which is usually 00:00:00 (midnight).
    定义为 24 小时（86,400,000 毫秒）。所有日期都从最早的时间开始，通常是 00：00：00（午夜）。
    """


class MatrixStatsMode(EnumBase):
    """
    The matrix_stats aggregation treats each document field as an independent sample. The mode parameter controls
    what array value the aggregation will use for array or multi-valued fields. This parameter can take one of the
    following:
        avg
            (default) Use the average of all values.
        min
            Pick the lowest value.
        max
            Pick the highest value.
        sum
            Use the sum of all values.
        median
            Use the median of all values.

    matrix_stats 聚合将每个文档字段视为一个独立的样本。mode 参数控制聚合将用于数组或多值字段的数组值。此参数可以采用以下选项之一：
        avg
            （默认）使用所有值的平均值。
        min
            选择最低值。
        max
            选择最高值。
        sum
            使用所有值的总和。
        median
            使用所有值的中位数。
    """
    avg = "avg"
    min = "min"
    max = "max"
    sum = "sum"
    median = "median"



































